Please carefully read the statements below and check each box if you agree with the declaration. If you do not check all boxes, your assignment will not be marked. If you make a false declaration on any of these points, you may be investigated for academic misconduct. Students found to have breached academic integrity may receive official warnings and/or serious academic penalties. Please read more about academic integrity here. If you are unsure about any of these points or feel your assessment might breach academic integrity, please contact your course coordinator for support. It is important that you DO NOT submit any assessment until you can complete the declaration truthfully.
By checking the boxes below, I declare the following:
I have not impersonated, or allowed myself to be impersonated by, any person for the purposes of this assessment
This assessment is my original work and no part of it has been copied from any other source except where due acknowledgement is made.
No part of this assessment has been written for me by any other person except where such collaboration has been authorised by the lecturer/teacher concerned.
Where this work is being submitted for individual assessment, I declare that it is my original work and that no part has been contributed by, produced by or in conjunction with another student.
I give permission for my assessment response to be reproduced, communicated compared and archived for the purposes of detecting plagiarism.
I give permission for a copy of my assessment to be retained by the university for review and comparison, including review by external examiners.
I understand that:
Plagiarism is the presentation of the work, idea or creation of another person as though it is your own. It is a form of cheating and is a very serious academic offence that may lead to exclusion from the University. Plagiarised material can be drawn from, and presented in, written, graphic and visual form, including electronic data and oral presentations. Plagiarism occurs when the origin of the material used is not appropriately cited.
Plagiarism includes the act of assisting or allowing another person to plagiarise or to copy my work.
I agree and acknowledge that:
I have read and understood the Declaration and Statement of Authorship above.
If I do not agree to the Declaration and Statement of Authorship in this context and all boxes are not checked, the assessment outcome is not valid for assessment purposes and will not be included in my final result for this course.
The aim of this study is two-fold: 1. To provide an effective visualization that educates the general public about the dangers of excessive antibiotic use. 2. To offer infectious disease doctors a quick yet comprehensive overview of antibiotic resistance in commonly encountered bacteria.
The following report aims to provide a detailed understanding of a dataset concerning antibiotic resistance across various bacterial species. This topic is of growing concern in the medical and scientific community.
| Column | Description |
|---|---|
| Bacterium Name | Scientific name of the bacteria. |
| Causes | Diseases or conditions that the bacteria typically cause. |
| Gram-negative? | Indicates whether the bacterium is Gram-negative (‘yes’ or ‘no’). |
| Individual Drugs | Resistance levels to specific antibiotics, represented as percentages. |
| Remarks | Additional comments about antibiotic resistance. |
| Resistance Score | A scale from 1-4 indicating the level of concern, with higher scores being more concerning. |
| N Antibiotics or Classes | Number of antibiotics or classes showing at least some resistance. |
| Average % Resistance | Calculated average resistance score across all considered antibiotics. |
This dataset serves as a snapshot that underlines the urgency for new antibiotics and effective strategies to manage antibiotic resistance. It calls for immediate action from both the medical community and policymakers.
The original data visualisation selected for the assignment was as follows:
The objective and audience of the original data visualisation chosen can be summarised as follows:
Objective
Audience
The visualisation chosen had the following three main issues:
Changes in new visualization: + Gestalt Laws: proximity (cluster together so a group?), similarity -> corrrect using symmetry to compare side by side, auto interpreted as the foreground (Figure Ground Principle) + Use Length to represent position - common scale - same scale but unaligned for 2 cat + Color - Hue (different color viz for nominal variables) + Use dodge method to have position adjustment. Other methods (filling, jiterring, nudging, stacking) + Faceting + Coordinate systems: Cartesian
data and aesthetic mappings,
• geometric objects,
• scales, and
• facet specification.
We have also touched on two other components:
• statistical transformations, and
• the coordinate system.
The following code was used to fix the issues identified in the original.
# Read and preprocess libraries
library(readxl)
library(dplyr)
library(stringr)
library(writexl)
# Load necessary libraries
library(ggplot2)
library(tidyr)
Data: In July 2014, the dataset on antibiotic resistance was sourced from informationisbeautiful.net. I have independently verified the integrity and accuracy of this data in 2023 against original sources, including the Centre for Disease Dynamics, World Health Organisation, and CDC (US data). Subsequent data processing and formatting to generate a tailored dataframe were conducted using the R programming language.
# Comment: Read Excel data from the first sheet
data <- read_excel("../data/antibiotic_data.xlsx", sheet = 1)
# Comment: Rename Columns
# Assuming the first row has column names that need renaming
names(data) <- str_replace_all(names(data), c(" " = "_", "%" = "percent", "-" = "_"))
# Comment: Save the cleaned data into a new CSV file
write.csv(data, "../data/cleaned_antibiotic_data.csv", row.names = FALSE)
data
## # A tibble: 20 × 49
## Antibiotic_…¹ by_In…² Antib…³ Penic…⁴ Penic…⁵ Amino…⁶ Amino…⁷ Other…⁸ Macro…⁹
## <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Adding up dr… "data … Indivi… all Penici… all Strept… Chlora… all
## 2 Bacterium na… "Cause… Gram n… <NA> <NA> <NA> <NA> <NA> <NA>
## 3 A. baumanii "\"Ira… yes x x 0.46 <NA> <NA> x
## 4 K. pneumoniae "pneum… yes <NA> <NA> 0.08 <NA> <NA> <NA>
## 5 E. faecium "urina… <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 6 N. gonorrhoe… "gonor… yes 0.3 x <NA> <NA> <NA> <NA>
## 7 Shigella "dysen… yes <NA> <NA> <NA> 0.56 0.14 <NA>
## 8 M. tuberculo… "tuber… <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 9 P. mirabilis "kidne… <NA> <NA> <NA> 0.09 <NA> <NA> <NA>
## 10 CoNS "food … <NA> <NA> x <NA> <NA> x <NA>
## 11 C. difficile "sever… <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 12 P. aeruginosa "lung,… yes <NA> <NA> 0.15 <NA> <NA> <NA>
## 13 S. pneumoniae "pneum… <NA> <NA> 0.08 <NA> <NA> <NA> 0.41
## 14 E. coli "food … yes <NA> <NA> 0.09 <NA> <NA> <NA>
## 15 S. aureus "boils… <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 16 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 17 gram-negativ… "stron… <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 18 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 19 <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA> <NA>
## 20 <NA> <NA> Date i… <NA> 1942.0 <NA> 1944.0 1949.0 <NA>
## # … with 40 more variables: Macrolides...10 <chr>, Other...11 <chr>,
## # Glycopeptides <chr>, Tetracyclines <chr>, Aminoglycosides...14 <chr>,
## # Penicillins...15 <chr>, `Penicillins_(Aminopenicillins)...16` <chr>,
## # Penicillins...17 <chr>, Nitroimidazoles <chr>,
## # `Penicillins_(Aminopenicillins)...19` <chr>, Sulfonamides <chr>,
## # `Cephalosporins_(First_generation)P` <chr>,
## # `Cephalosporins_(First_generation)` <chr>, Aminoglycosides...23 <chr>, …
## # ℹ Use `colnames()` to see all variable names
# Load data (assuming it's saved in a file called "data.csv")
df <- read.csv("../data/cleaned_antibiotic_data.csv", stringsAsFactors = FALSE, header = TRUE)
# Handle missing values:
# Replace "x" with NA and convert to numeric
df[df == "x"] <- NA
df[4:ncol(df)] <- lapply(df[4:ncol(df)], as.numeric)
# Handle columns:
# The first three columns seem to be about the bacterium name, its common diseases, and its gram-negative status.
# For better clarity, we will rename them.
colnames(df)[1:3] <- c("BacteriumName", "Causes", "GramNegative")
# Removing rows that are not relevant to our analysis:
# Rows that contain only NAs or meta-information are removed.
df <- df %>% filter(!is.na(BacteriumName))
# As a suggestion, you might want to separate the antibiotics based on their family/group.
# However, this would require domain knowledge about which antibiotic belongs to which group.
# You can save the cleaned data to a new CSV file if desired.
write.csv(df, "../data/cleaned_data.csv", row.names = FALSE)
# The data is now cleaned and saved as "cleaned_data.csv".
df
## BacteriumName
## 1 Adding up drug resistance
## 2 Bacterium name
## 3 A. baumanii
## 4 K. pneumoniae
## 5 E. faecium
## 6 N. gonorrhoeae
## 7 Shigella
## 8 M. tuberculosis
## 9 P. mirabilis
## 10 CoNS
## 11 C. difficile
## 12 P. aeruginosa
## 13 S. pneumoniae
## 14 E. coli
## 15 S. aureus
## 16 gram-negative bacteria
## Causes
## 1 data are % of bacteria that are resistant, US\nx = resistance, but unquantified
## 2 Causes
## 3 "Iraqibacter" - pneumonia, meningitis
## 4 pneumonia, bronchitis, urinary infections
## 5 urinary infections
## 6 gonorrhoea
## 7 dysentry
## 8 tuberculosis
## 9 kidney stones, proteus
## 10 food poisoning
## 11 severe diarrhoea, colitis
## 12 lung, urinary, skin, wound & blood infections
## 13 pneumonia, meningitis & many other infections
## 14 food poisoning
## 15 boils, sinusitis, food poisoning
## 16 strong membrane, more resistant
## GramNegative Penicillins...4 Penicillins...5 Aminoglycosides...6
## 1 Individual drug NA NA NA
## 2 Gram negative? NA NA NA
## 3 yes NA NA 0.46
## 4 yes NA NA 0.08
## 5 <NA> NA NA NA
## 6 yes 0.3 NA NA
## 7 yes NA NA NA
## 8 <NA> NA NA NA
## 9 <NA> NA NA 0.09
## 10 <NA> NA NA NA
## 11 <NA> NA NA NA
## 12 yes NA NA 0.15
## 13 <NA> NA 0.08 NA
## 14 yes NA NA 0.09
## 15 <NA> NA NA NA
## 16 <NA> NA NA NA
## Aminoglycosides...7 Other...8 Macrolides...9 Macrolides...10 Other...11
## 1 NA NA NA NA NA
## 2 NA NA NA NA NA
## 3 NA NA NA NA NA
## 4 NA NA NA NA NA
## 5 NA NA NA NA NA
## 6 NA NA NA NA NA
## 7 0.56 0.14 NA NA NA
## 8 NA NA NA NA 0.09
## 9 NA NA NA NA NA
## 10 NA NA NA NA NA
## 11 NA NA NA NA NA
## 12 NA NA NA NA NA
## 13 NA NA 0.41 NA NA
## 14 NA NA NA NA NA
## 15 NA NA NA NA NA
## 16 NA NA NA NA NA
## Glycopeptides Tetracyclines Aminoglycosides...14 Penicillins...15
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA NA NA
## 4 NA NA NA NA
## 5 0.75 NA NA NA
## 6 NA NA NA NA
## 7 NA 0.45 0.009 NA
## 8 NA NA NA NA
## 9 NA NA NA NA
## 10 0.00 0.16 NA 0.63
## 11 0.11 0.03 NA NA
## 12 NA NA NA NA
## 13 NA NA NA NA
## 14 NA NA NA NA
## 15 NA NA NA NA
## 16 NA NA NA NA
## Penicillins_.Aminopenicillins....16 Penicillins...17 Nitroimidazoles
## 1 NA NA NA
## 2 NA NA NA
## 3 NA NA NA
## 4 NA NA NA
## 5 NA NA NA
## 6 NA NA NA
## 7 NA NA NA
## 8 NA NA NA
## 9 0.22 NA NA
## 10 NA NA NA
## 11 NA NA 0
## 12 NA NA NA
## 13 NA NA NA
## 14 0.45 NA NA
## 15 NA 0.51 NA
## 16 NA NA NA
## Penicillins_.Aminopenicillins....19 Sulfonamides
## 1 NA NA
## 2 NA NA
## 3 NA NA
## 4 NA NA
## 5 NA NA
## 6 NA NA
## 7 0.78 0.47
## 8 NA NA
## 9 NA NA
## 10 NA NA
## 11 NA NA
## 12 NA NA
## 13 NA NA
## 14 NA NA
## 15 NA NA
## 16 NA NA
## Cephalosporins_.First_generation.P Cephalosporins_.First_generation.
## 1 NA NA
## 2 NA NA
## 3 NA NA
## 4 NA NA
## 5 NA NA
## 6 NA NA
## 7 NA 0.06
## 8 NA NA
## 9 NA NA
## 10 NA NA
## 11 NA NA
## 12 NA NA
## 13 NA NA
## 14 NA NA
## 15 NA NA
## 16 NA NA
## Aminoglycosides...23 Fluoroquinolones Fluroquinolones...25 Rifamycin
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA 0.58 NA 0.000
## 4 NA 0.11 NA NA
## 5 0.190 NA NA NA
## 6 NA NA NA NA
## 7 0.002 0.02 0.01 NA
## 8 NA NA NA NA
## 9 NA 0.28 NA NA
## 10 NA 0.50 NA NA
## 11 NA NA NA 0.100
## 12 NA 0.27 NA NA
## 13 NA NA NA NA
## 14 NA 0.33 NA NA
## 15 NA NA NA 0.008
## 16 NA NA NA NA
## Lincosamides Sulfonamides_._other. Aminoglycosides...29 Penicillins...30
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA 0e+00 NA
## 4 NA 0.15 NA NA
## 5 NA NA NA NA
## 6 NA NA NA NA
## 7 NA 0.46 6e-04 0.02
## 8 NA NA NA NA
## 9 NA 0.27 NA NA
## 10 0.33 0.34 NA NA
## 11 0.28 NA NA NA
## 12 NA NA NA NA
## 13 NA NA NA NA
## 14 NA 0.25 NA NA
## 15 NA NA NA NA
## 16 NA NA NA NA
## Cephalosporins_.Third_generation....31
## 1 NA
## 2 NA
## 3 NA
## 4 0.23
## 5 NA
## 6 NA
## 7 NA
## 8 NA
## 9 0.02
## 10 NA
## 11 NA
## 12 NA
## 13 NA
## 14 0.15
## 15 NA
## 16 NA
## Cephalosporins_.Third_generation....32
## 1 NA
## 2 NA
## 3 NA
## 4 NA
## 5 NA
## 6 0.004
## 7 0.000
## 8 NA
## 9 NA
## 10 NA
## 11 NA
## 12 NA
## 13 NA
## 14 NA
## 15 NA
## 16 NA
## Cephalosporins_.Third_generation....33 Carbapenems...34 Carbapenems...35
## 1 NA NA NA
## 2 NA NA NA
## 3 0.52 0.41 NA
## 4 NA 0.11 NA
## 5 NA NA NA
## 6 NA NA NA
## 7 NA NA NA
## 8 NA NA NA
## 9 NA NA NA
## 10 NA NA NA
## 11 NA NA NA
## 12 0.10 0.14 NA
## 13 NA NA NA
## 14 NA NA NA
## 15 NA NA NA
## 16 NA NA NA
## Penicillins...36 ...37 Fluroquinolones...38 Fluroquinolones...39
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 0.25 NA NA NA
## 4 NA NA NA NA
## 5 NA NA NA NA
## 6 0.13 NA 0.1400 NA
## 7 NA 6e-04 0.0006 NA
## 8 NA NA NA NA
## 9 NA NA NA NA
## 10 NA NA NA NA
## 11 NA NA NA 0.39
## 12 NA NA NA NA
## 13 NA NA NA NA
## 14 NA NA NA NA
## 15 NA NA NA NA
## 16 NA NA NA NA
## Penicillins...40 ...41 Multi_drug Remarks Resistance_score ...45
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA 0.510 NA 4 NA
## 4 NA NA 0.060 NA 2 NA
## 5 NA NA NA NA 1 NA
## 6 NA NA 0.300 NA 3 NA
## 7 NA NA 0.640 NA 4 NA
## 8 NA NA 0.600 NA 3 NA
## 9 NA NA 0.006 NA 2 NA
## 10 NA NA 0.130 NA 3 NA
## 11 NA NA NA NA 3 NA
## 12 0.12 NA 0.100 NA 2 NA
## 13 NA NA 0.080 NA 1 NA
## 14 NA NA 0.015 NA 2 NA
## 15 NA NA NA NA 1 NA
## 16 NA NA NA NA NA NA
## N_antibiotics_or_classes Average_percent_resistance ...48 Sources
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 18 0.3171429 NA NA
## 4 5 0.1360000 NA NA
## 5 2 0.4700000 NA NA
## 6 6 0.1435000 NA NA
## 7 16 0.1864250 NA NA
## 8 7 0.0900000 NA NA
## 9 5 0.1760000 NA NA
## 10 9 0.3266667 NA NA
## 11 7 0.1516667 NA NA
## 12 5 0.1560000 NA NA
## 13 2 0.2450000 NA NA
## 14 5 0.2540000 NA NA
## 15 1 0.2590000 NA NA
## 16 NA NA NA NA
The following plot fixes the main issues in the original.
# Data
antibiotic_resistance_df <- data.frame(
Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. faecium', 'N. gonorrhoeae', 'Shigella',
'M. tuberculosis', 'P. mirabilis', 'CoNS', 'C. difficile',
'P. aeruginosa', 'S. pneumoniae', 'E. coli', 'S. aureus'),
Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis, urinary infections', 'urinary infections',
'gonorrhoea', 'dysentry', 'tuberculosis', 'kidney stones, proteus', 'food poisoning',
'severe diarrhoea, colitis', 'lung, urinary, skin, wound & blood infections',
'pneumonia, meningitis & many other infections', 'food poisoning', 'boils, sinusitis, food poisoning'),
Gram_negative = c('yes', 'yes', 'no', 'yes', 'yes', 'no', 'yes', 'no', 'no', 'yes', 'no', 'yes', 'no'),
Penicillin = c(46, 8, NA, 30, NA, NA, 9, NA, NA, 15, 8, 9, NA),
Streptomycin = c(NA, NA, 75, NA, 56, 9, NA, NA, NA, NA, NA, NA, NA),
Chloramphenicol = c(NA, NA, NA, NA, 14, NA, NA, NA, 3, NA, NA, NA, NA),
Erythromycin = c(58, 11, 19, NA, 45, NA, 22, 16, 11, 27, NA, 45, 51),
Isoniazid = c(NA, NA, NA, NA, 0.9, NA, NA, NA, NA, NA, NA, NA, 0.8),
Vancomycin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
Tetracycline = c(NA, NA, NA, NA, 78, NA, NA, NA, NA, NA, NA, NA, NA),
Kanamycin = c(NA, NA, NA, NA, 47, NA, NA, NA, NA, NA, NA, NA, NA),
Oxacillin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
Methicillin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
Metronidazole = c(NA, NA, NA, NA, NA, NA, NA, NA, 10, NA, NA, NA, NA),
Ampicillin = c(NA, NA, NA, NA, NA, NA, NA, NA, 28, NA, NA, NA, NA),
Sulfamethoxazole = c(NA, NA, NA, NA, 6, NA, NA, NA, NA, NA, NA, 15, NA),
Cefalotin = c(NA, NA, NA, NA, 0.2, NA, 2, NA, NA, NA, NA, NA, NA),
Gentamicin = c(NA, NA, NA, NA, 2, NA, 1, NA, NA, 10, NA, NA, NA),
Nalidixic_acid = c(NA, NA, NA, NA, 1, NA, NA, NA, NA, 14, NA, NA, NA),
Rifampicin = c(NA, NA, NA, NA, 46, NA, NA, NA, NA, NA, NA, NA, NA),
Clindamycin = c(NA, NA, NA, NA, 0.06, NA, NA, NA, NA, NA, NA, NA, NA),
Trimethoprim_sulfa = c(NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA),
Amikacin = c(NA, NA, NA, NA, 0, NA, NA, NA, NA, NA, NA, NA, NA),
Amoxicillin_clavulanic_acid = c(NA, NA, NA, NA, 0.06, NA, NA, NA, NA, NA, NA, NA, NA),
Ceftriaxone = c(NA, NA, NA, NA, 0.06, NA, NA, NA, NA, NA, NA, NA, NA),
Ceftazidime = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
Imipenem = c(52, NA, NA, NA, 64, 60, 0.6, 13, 39, 12, 8, 1.5, NA),
Ceftiofur = c(41, NA, NA, NA, NA, NA, NA, NA, NA, 10, NA, NA, NA),
Ciprofloxacin = c(25, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
Moxifloxacin = c(NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA),
Piperacillin_tazobactam = c(51, 6, NA, 30, NA, NA, NA, NA, NA, 10, NA, NA, NA)
)
# Antibiotic Introduction Dates
antibiotic_intro_dates <- data.frame(
Antibiotic = c('Penicillin', 'Streptomycin', 'Chloramphenicol', 'Erythromycin', 'Isoniazid',
'Vancomycin', 'Tetracycline', 'Kanamycin', 'Oxacillin', 'Methicillin', 'Metronidazole',
'Ampicillin', 'Sulfamethoxazole', 'Cefalotin', 'Gentamicin', 'Nalidixic_acid',
'Rifampicin', 'Clindamycin', 'Trimethoprim_sulfa', 'Amikacin', 'Amoxicillin_clavulanic_acid',
'Ceftriaxone', 'Ceftazidime', 'Imipenem', 'Ceftiofur', 'Ciprofloxacin', 'Moxifloxacin',
'Piperacillin_tazobactam'),
Date_introduced = c(1942, 1944, 1949, 1952, 1952, 1955, 1955, 1958, 1959, 1960, 1960, 1961, 1961, 1964,
1964, 1967, 1967, 1968, 1968, 1976, 1981, 1982, 1983, 1985, 1987, 1987, 1987, 1989)
)
# View the dataframes
head(antibiotic_resistance_df)
## Bacterium_name Causes Gram_negative
## 1 A. baumanii pneumonia, meningitis yes
## 2 K. pneumoniae pneumonia, bronchitis, urinary infections yes
## 3 E. faecium urinary infections no
## 4 N. gonorrhoeae gonorrhoea yes
## 5 Shigella dysentry yes
## 6 M. tuberculosis tuberculosis no
## Penicillin Streptomycin Chloramphenicol Erythromycin Isoniazid Vancomycin
## 1 46 NA NA 58 NA NA
## 2 8 NA NA 11 NA NA
## 3 NA 75 NA 19 NA NA
## 4 30 NA NA NA NA NA
## 5 NA 56 14 45 0.9 NA
## 6 NA 9 NA NA NA NA
## Tetracycline Kanamycin Oxacillin Methicillin Metronidazole Ampicillin
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 78 47 NA NA NA NA
## 6 NA NA NA NA NA NA
## Sulfamethoxazole Cefalotin Gentamicin Nalidixic_acid Rifampicin Clindamycin
## 1 NA NA NA NA NA NA
## 2 NA NA NA NA NA NA
## 3 NA NA NA NA NA NA
## 4 NA NA NA NA NA NA
## 5 6 0.2 2 1 46 0.06
## 6 NA NA NA NA NA NA
## Trimethoprim_sulfa Amikacin Amoxicillin_clavulanic_acid Ceftriaxone
## 1 NA NA NA NA
## 2 NA NA NA NA
## 3 NA NA NA NA
## 4 NA NA NA NA
## 5 2 0 0.06 0.06
## 6 NA NA NA NA
## Ceftazidime Imipenem Ceftiofur Ciprofloxacin Moxifloxacin
## 1 NA 52 41 25 NA
## 2 NA NA NA NA NA
## 3 NA NA NA NA NA
## 4 NA NA NA NA NA
## 5 NA 64 NA NA NA
## 6 NA 60 NA NA NA
## Piperacillin_tazobactam
## 1 51
## 2 6
## 3 NA
## 4 30
## 5 NA
## 6 NA
head(antibiotic_intro_dates)
## Antibiotic Date_introduced
## 1 Penicillin 1942
## 2 Streptomycin 1944
## 3 Chloramphenicol 1949
## 4 Erythromycin 1952
## 5 Isoniazid 1952
## 6 Vancomycin 1955
This heatmap provides a quick visual representation of resistance percentages for various bacteria against different antibiotics. The darker the color, the higher the resistance. The antibiotics are also ordered based on their introduction dates, which can give an idea about the evolution of resistance over time.
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic),]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +
scale_fill_gradient(low = "lightblue", high = "darkblue", name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(
axis.text.x = element_text(angle = 90, hjust = 1, size = 12, margin = margin(t = 10)), # Extra space between x-axis title and values
axis.text.y = element_text(size = 12, margin = margin(r = 10)), # Extra space between y-axis title and values
axis.title.x = element_text(face = "bold", size = 14),
axis.title.y = element_text(face = "bold", size = 14),
plot.margin = margin(10, 10, 80, 10),
panel.grid.major = element_line(colour = "gray", size = 0.25),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
) +
scale_x_discrete(position = "top")
# Display plot
print(p)
# Display the title text at the top-left of the plot
grid::grid.text("ANTIBIOTIC CHALLENGE: BACTERIAL RESISTANCE OVERVIEW", x = 0.01, y = 0.99, just = c("left", "top"), gp = grid::gpar(col = "blue", fontsize = 20, fontface = "bold"))
# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data) | Designed by Thu Tran", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic),]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +
scale_fill_gradient(low = "lightblue", high = "darkblue", name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(
axis.text.x = element_text(angle = 90, hjust = 1, size = 12, margin = margin(t = 10)), # Extra space between x-axis title and values
axis.text.y = element_text(size = 12, margin = margin(r = 10)), # Extra space between y-axis title and values
axis.title.x = element_text(face = "bold", size = 14),
axis.title.y = element_text(face = "bold", size = 14),
plot.title = element_text(face = "bold", color = "blue", size = 18), # Even bolder and larger plot title
plot.margin = margin(10, 10, 80, 10),
panel.grid.major = element_line(colour = "gray", size = 0.25),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
) +
scale_x_discrete(position = "top") +
ggtitle("ANTIBIOTIC CHALLENGE: BACTERIAL RESISTANCE OVERVIEW")
# Display plot
print(p)
# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data) | Designed by Thu Tran (tnathu-ai)", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic),]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +
scale_fill_gradient(low = "lightblue", high = "darkblue", name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(
axis.text.x = element_text(angle = 90, hjust = 1, size = 12, margin = margin(t = 10)), # Extra space between x-axis title and values
axis.text.y = element_text(size = 12, margin = margin(r = 10)), # Extra space between y-axis title and values
axis.title.x = element_text(face = "bold", size = 14),
axis.title.y = element_text(face = "bold", size = 14),
plot.title = element_text(face = "bold", color = "blue", size = 16), # Bold and blue plot title
plot.margin = margin(10, 10, 80, 10),
panel.grid.major = element_line(colour = "gray", size = 0.25),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Various Antibiotics to Bacteria")
# Display plot
print(p)
# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid)
# Define the OkabeIto palette
OkabeIto <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7", "#000000")
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +
scale_fill_gradient(low = OkabeIto[1], high = OkabeIto[8], name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(
axis.text.x = element_text(angle = 90, hjust = 1, size = 12, margin = margin(t = 5)), # Margin to space out x axis values
axis.text.y = element_text(size = 12, margin = margin(r = 5)), # Margin to space out y axis values
axis.title.x = element_text(face = "bold", size = 14, margin = margin(t = 15)), # Bold x axis title
axis.title.y = element_text(face = "bold", size = 14, margin = margin(r = 15)), # Bold y axis title
plot.title = element_text(face = "bold", color = "blue", size = 16), # Highlight main title in bold blue
plot.margin = margin(10, 10, 80, 10),
panel.grid.major = element_line(colour = "gray", size = 0.25),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Various Antibiotics to Bacteria")
# Display plot
print(p)
# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(
axis.text.x = element_text(angle = 90, hjust = 1, size = 12), # Bigger font size for x axis values
axis.text.y = element_text(size = 12), # Bigger font size for y axis values
axis.title.x = element_text(face = "bold", size = 14), # Bold x axis title
axis.title.y = element_text(face = "bold", size = 14), # Bold y axis title
plot.margin = margin(10, 10, 80, 10),
panel.grid.major = element_line(colour = "gray", size = 0.25),
plot.background = element_rect(fill = "white", color = NA),
panel.background = element_rect(fill = "white", color = NA)
) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Various Antibiotics to Bacteria")
# Display plot
print(p)
# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
library(grid) # Ensure the grid package is loaded for grid.text
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) + # Adjust width and height to space out the tiles
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 80, 10), # Adjust bottom margin to make space for both texts
panel.grid.major = element_line(colour = "gray", size = 0.25), # Make the grid lines less obvious
plot.background = element_rect(fill = "white", color = NA), # White background with no border
panel.background = element_rect(fill = "white", color = NA)) + # White background with no border
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics")
# Display plot
print(p)
# Display the main source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.02, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
# Display the additional information below the main source text
grid::grid.text("Original image: informationisbeautiful.net | Data collected by July 2014", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
p <- ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) + # Adjust width and height to space out the tiles
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Individual Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 60, 10), # Adjust bottom margin to make space for source text
panel.grid.major = element_line(colour = "gray", size = 0.25), # Make the grid lines less obvious
plot.background = element_rect(fill = "white", color = NA), # White background with no border
panel.background = element_rect(fill = "white", color = NA)) + # White background with no border
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics")
# Display plot
print(p)
# Display the source text below the plot
grid::grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", x = 0.01, y = 0.01, just = c("left", "bottom"), gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic"))
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.9, height = 0.9) + # Increased spacing between tiles
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10),
panel.grid.major = element_line(color = "grey85")) + # Lightened grid lines
scale_x_discrete(position = "top", expand = c(0.05, 0.05)) + # Added a bit of spacing around the x-axis
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotation_custom(
ggplotGrob(
ggplot() +
theme_void() +
annotate("text", x = 0.5, y = 0.5, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)", color = "gray", size = 5, fontface = "italic")
),
xmin = -Inf, xmax = -1, ymin = -Inf, ymax = -1.5
)
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white", width = 0.7, height = 0.7) + # Adjust width and height to space out the tiles
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10),
panel.grid.major = element_line(colour = "gray", size = 0.25), # Make the grid lines less obvious
plot.background = element_rect(fill = "white", color = NA), # White background with no border
panel.background = element_rect(fill = "white", color = NA)) + # White background with no border
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotation_custom(
grob = grid::textGrob(label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
gp = grid::gpar(col = "gray", fontsize = 10, fontface = "italic")),
xmin = -Inf, xmax = -Inf, ymin = -Inf, ymax = -Inf
)
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$display_name <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that display_name is a factor and ordered based on variable
melted_df$display_name <- factor(melted_df$display_name, levels = unique(melted_df$display_name[order(melted_df$variable)]))
# Plotting the heatmap
ggplot(melted_df, aes(x = display_name, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
annotate("text", x = 0, y = -1.5, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Remove underscores from antibiotic names
melted_df$variable <- gsub("_", " ", melted_df$variable)
# Append introduction date to antibiotic name
melted_df$variable_with_date <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")
# Ensure that variable_with_date is a factor
melted_df$variable_with_date <- as.factor(melted_df$variable_with_date)
# Plotting the heatmap
ggplot(melted_df, aes(x = variable_with_date, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 60, 10)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
annotate("text", x = 1, y = -2, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name and remove underscores
melted_df$variable <- paste(gsub("_", " ", melted_df$variable), "(", melted_df$Date_introduced, ")")
# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
annotate("text", x = 0, y = -1, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic") +
annotate("text", x = 0, y = -Inf, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
vjust = 0, hjust = 0, color = "gray", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
ordered_antibiotics <- antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)]
melted_df$variable <- factor(melted_df$variable, levels = ordered_antibiotics)
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name
melted_df$variable_label <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")
# Plotting the heatmap
ggplot(melted_df, aes(x = variable_label, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = -Inf, y = -Inf, hjust = 0, vjust = 0, label = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)",
color = "gray", size = 3, fontface = "italic") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name
melted_df$variable <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")
# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 90, hjust = 1, size = 8),
plot.margin = margin(10, 10, 40, 10)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Append introduction date to antibiotic name
melted_df$variable <- paste(melted_df$variable, "(", melted_df$Date_introduced, ")")
# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "grey90", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))
# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)
# Convert Date_introduced to character if it isn't
melted_df$Date_introduced <- as.character(melted_df$Date_introduced)
# Create a label that combines the antibiotic name and its introduction date
melted_df$label <- paste0(melted_df$variable, "\n(", melted_df$Date_introduced, ")")
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = brewer.pal(9, "Spectral")[1],
high = brewer.pal(9, "Spectral")[9], name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 45, hjust = 1, size = 8)) +
scale_x_discrete(labels = melted_df$label, position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))
# Ensure that variable is a factor
melted_df$variable <- as.factor(melted_df$variable)
# Convert Date_introduced to character if it isn't
melted_df$Date_introduced <- as.character(melted_df$Date_introduced)
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
geom_text(aes(label = Date_introduced), vjust = 1.5, color = "black", size = 2.5) +
scale_fill_gradient(low = brewer.pal(9, "Spectral")[1],
high = brewer.pal(9, "Spectral")[9], name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics") +
annotate("text", x = Inf, y = Inf, label = "No major new antibiotics developed for 20 years",
vjust = 2, hjust = 1.5, color = "black", size = 3, fontface = "italic")
library(ggplot2)
library(reshape2)
library(RColorBrewer) # To use color palettes
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))
# Create new labels for the x-axis that combine the antibiotic name with its introduction date
melted_df$label <- paste(melted_df$variable, melted_df$Date_introduced, sep = "\n")
# Plotting the heatmap
ggplot(melted_df, aes(x = label, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_distiller(palette = "RdYlBu", direction = 1, name = "Resistance %") + # Use a color-blind friendly palette
labs(x = "Antibiotics\n(Date Introduced)", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics")
library(ggplot2)
library(reshape2)
# Melt the data frame to long format for ggplot
melted_df <- melt(antibiotic_resistance_df, id.vars = c("Bacterium_name", "Causes", "Gram_negative"))
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic")
# Ensure that the introduction dates are unique
antibiotic_intro_dates <- antibiotic_intro_dates[!duplicated(antibiotic_intro_dates$Antibiotic), ]
# Create an ordered factor for the Antibiotic based on Date_introduced
antibiotic_intro_dates$Antibiotic <- factor(antibiotic_intro_dates$Antibiotic,
levels = antibiotic_intro_dates$Antibiotic[order(antibiotic_intro_dates$Date_introduced)])
# Merge the melted dataframe with the antibiotic introduction date
melted_df <- merge(melted_df, antibiotic_intro_dates, by.x = "variable", by.y = "Antibiotic", all.x = TRUE)
# Order antibiotics by introduction date for plotting
melted_df$variable <- factor(melted_df$variable, levels = levels(antibiotic_intro_dates$Antibiotic))
# Continue with the rest of the plotting code
# Plotting the heatmap
ggplot(melted_df, aes(x = variable, y = Bacterium_name)) +
geom_tile(aes(fill = value), color = "white") +
scale_fill_gradient(low = "white", high = "red", name = "Resistance %") +
labs(x = "Antibiotics", y = "Bacterium") +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
scale_x_discrete(position = "top") +
ggtitle("Resistance of Bacteria to Various Antibiotics")
# Data
antibiotic_resistance_df <- data.frame(
Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. faecium', 'N. gonorrhoeae', 'Shigella',
'M. tuberculosis', 'P. mirabilis', 'CoNS', 'C. difficile',
'P. aeruginosa', 'S. pneumoniae', 'E. coli', 'S. aureus'),
Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'urinary infections',
'gonorrhoea', 'dysentry', 'tuberculosis', 'kidney stones, proteus', 'food poisoning',
'severe diarrhoea, colitis', 'lung, urinary, skin, wound & blood infections',
'pneumonia, meningitis & many other infections', 'food poisoning', 'boils, sinusitis, food poisoning'),
Gram_negative = c('yes', 'yes', 'no', 'yes', 'yes', 'no', 'yes', 'no', 'no', 'yes', 'no', 'yes', 'no'),
Penicillin = c(46, 8, NA, 30, NA, NA, 9, NA, NA, 15, 8, 9, NA),
Streptomycin = c(NA, NA, NA, NA, 56, NA, NA, NA, NA, NA, NA, NA, NA),
Erythromycin = c(58, 11, 19, NA, NA, 9, NA, 16, 11, 27, 41, NA, 51)
# Add other antibiotics columns as needed
)
# View the dataframe
head(antibiotic_resistance_df)
## Bacterium_name Causes Gram_negative Penicillin Streptomycin
## 1 A. baumanii pneumonia, meningitis yes 46 NA
## 2 K. pneumoniae pneumonia, bronchitis yes 8 NA
## 3 E. faecium urinary infections no NA NA
## 4 N. gonorrhoeae gonorrhoea yes 30 NA
## 5 Shigella dysentry yes NA 56
## 6 M. tuberculosis tuberculosis no NA NA
## Erythromycin
## 1 58
## 2 11
## 3 19
## 4 NA
## 5 NA
## 6 9
library(ggplot2)
library(tidyr)
library(RColorBrewer)
# Data
antibiotic_resistance_df <- data.frame(
Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. faecium'),
Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'urinary infections'),
Gram_negative = c('yes', 'yes', 'no'),
Penicillin = c(46, 8, NA),
Streptomycin = c(NA, NA, 75),
Erythromycin = c(58, 11, 19)
)
# Reshape data for plotting
df_long <- antibiotic_resistance_df %>%
gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)
# Colorblind-friendly palette
cb_palette <- brewer.pal(n = 3, name = "Set2")
plot <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
labs(
title = "Antibiotic Resistance Across Different Bacteria",
subtitle = "Faceted by Gram-negative Status",
x = "Bacterium",
y = "Resistance (%)",
caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)"
) +
scale_fill_manual(values = cb_palette) +
theme_minimal() +
theme(legend.position = "top", plot.caption = element_text(hjust = 1, color = "gray"))
print(plot)
library(ggplot2)
library(tidyr)
# Updated data
antibiotic_resistance_df <- data.frame(
Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. coli', 'E. faecium', 'S. aureus', 'P. aeruginosa', 'Enterococcus'),
Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'gastrointestinal infections', 'urinary infections', 'skin infections', 'sepsis, skin infections', 'urinary tract, bloodstream infections'),
Gram_negative = c('yes', 'yes', 'yes', 'no', 'no', 'yes', 'no'),
Penicillin = c(46, 8, 12, NA, 90, 23, NA),
Streptomycin = c(NA, NA, 75, 85, 15, 26, 50),
Erythromycin = c(58, 11, 19, 30, 45, 40, 38)
)
# Reshape data for plotting
df_long <- antibiotic_resistance_df %>%
gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)
# Comprehensive Visualization
plot <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
labs(
title = "Antibiotic Resistance Across Different Bacteria",
subtitle = "Faceted by Gram-negative Status",
x = "Bacterium",
y = "Resistance (%)",
caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/"
) +
theme_minimal() +
theme(legend.position = "top", plot.caption = element_text(hjust = 1, color = "gray"))
# Display the plot
print(plot)
# Save the plot to the ../images directory
ggsave(filename = "../images/antibiotic_resistance_plot.png", plot = plot, width = 20, height = 15)
library(RColorBrewer)
# Colorblind-friendly palette for 3 groups
cb_palette <- brewer.pal(n = 3, name = "Set2")
plot <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
labs(
title = "Antibiotic Resistance Across Different Bacteria",
subtitle = "Faceted by Gram-negative Status",
x = "Bacterium",
y = "Resistance (%)",
caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/"
) +
scale_fill_manual(values = cb_palette) +
theme_minimal() +
theme(legend.position = "top", plot.caption = element_text(hjust = 1, color = "gray"))
print(plot)
Reconstructed plot.
library(ggplot2)
library(tidyr)
# Updated data
antibiotic_resistance_df <- data.frame(
Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. coli', 'E. faecium', 'S. aureus', 'P. aeruginosa', 'Enterococcus'),
Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'gastrointestinal infections', 'urinary infections', 'skin infections', 'sepsis, skin infections', 'urinary tract, bloodstream infections'),
Gram_negative = c('yes', 'yes', 'yes', 'no', 'no', 'yes', 'no'),
Penicillin = c(46, 8, 12, NA, 90, 23, NA),
Streptomycin = c(NA, NA, 75, 85, 15, 26, 50),
Erythromycin = c(58, 11, 19, 30, 45, 40, 38)
)
# Reshape data for plotting
df_long <- antibiotic_resistance_df %>%
gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)
# Comprehensive Visualization
ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
labs(
title = "Antibiotic Resistance Across Different Bacteria",
subtitle = "Faceted by Gram-negative Status",
x = "Bacterium",
y = "Resistance (%)",
caption = "Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/"
) +
theme_minimal() +
theme(legend.position = "top", plot.caption = element_text(hjust = 1))
library(ggplot2)
library(tidyr)
library(grid)
# Updated data
antibiotic_resistance_df <- data.frame(
Bacterium_name = c('A. baumanii', 'K. pneumoniae', 'E. coli', 'E. faecium', 'S. aureus', 'P. aeruginosa', 'Enterococcus'),
Causes = c('pneumonia, meningitis', 'pneumonia, bronchitis', 'gastrointestinal infections', 'urinary infections', 'skin infections', 'sepsis, skin infections', 'urinary tract, bloodstream infections'),
Gram_negative = c('yes', 'yes', 'yes', 'no', 'no', 'yes', 'no'),
Penicillin = c(46, 8, 12, NA, 90, 23, NA),
Streptomycin = c(NA, NA, 75, 85, 15, 26, 50),
Erythromycin = c(58, 11, 19, 30, 45, 40, 38)
)
# Reshape data for plotting
df_long <- antibiotic_resistance_df %>%
gather(key = 'Antibiotic', value = 'Resistance', Penicillin, Streptomycin, Erythromycin)
# Create the plot and save it to an object
p <- ggplot(df_long, aes(x = Bacterium_name, y = Resistance, fill = Antibiotic)) +
geom_bar(stat = "identity", position = "dodge") +
facet_wrap(~Gram_negative, scales = "free", ncol = 2) +
labs(
title = "Antibiotic Resistance Across Different Bacteria",
subtitle = "Faceted by Gram-negative Status",
x = "Bacterium",
y = "Resistance (%)"
) +
theme_minimal() +
theme(legend.position = c(1, 1), legend.justification = c(1, 1))
# Print the plot
print(p)
# Add the source text using grid package
grid.text("Sources: Centre for Disease Dynamics, World Health Organisation, CDC (US data)\nInspiration from: https://informationisbeautiful.net/visualizations/antibiotic-resistance/",
x = 1, y = 1.03, hjust = 1, gp = gpar(col = "darkgray", fontsize = 8))
The reference to the original data visualisation choose, the data source(s) used for the reconstruction and any other sources used for this assignment are as follows:
ACMA Research and Analysis Section. (2015). Australians get mobile. Retrieved August 13, 2019, from Australian Communications and Media Authority website: https://www.acma.gov.au/theACMA/engage-blogs/engage-blogs/Research-snapshots/Australians-get-mobile
Pneumococcal Disease and Antibiotic Resistance | CDC. (2022, January 24). Www.cdc.gov. https://www.cdc.gov/pneumococcal/clinicians/drug-resistance.html
About Division of Bacterial Diseases | CDC. (2021, November 30). Www.cdc.gov. https://www.cdc.gov/ncird/dbd.html
Immunization and Respiratory Diseases (NCIRD) Home. (2020). https://www.cdc.gov/ncird/
Antibiotic - New World Encyclopedia. (n.d.). Www.newworldencyclopedia.org. Retrieved September 16, 2023, from https://www.newworldencyclopedia.org/entry/Antibiotic
Antibiotics | Society | The Guardian. (n.d.). The Guardian. Retrieved September 16, 2023, from https://www.theguardian.com/society/antibiotics
Antibiotics | Society | The Guardian. (n.d.). The Guardian. Retrieved September 16, 2023, from https://www.theguardian.com/society/antibiotics
Drug-Resistant Superbugs Sweeping Across Europe - Slashdot. (2011, November 18). Science.slashdot.org. https://science.slashdot.org/story/11/11/18/0430245/drug-resistant-superbugs-sweeping-across-europe
Drug-Resistant Superbugs Sweeping Across Europe - Slashdot. (2011, November 18). Science.slashdot.org. https://science.slashdot.org/story/11/11/18/0430245/drug-resistant-superbugs-sweeping-across-europe
NHS. (2018, August 16). Medicines A-Z. Nhs.uk. https://www.nhs.uk/medicines/
Wise, R., Hart, T., Cars, O., Streulens, M., Helmuth, R., Huovinen, P., & Sprenger, M. (1998). Antimicrobial resistance. BMJ, 317(7159), 609–610. https://doi.org/10.1136/bmj.317.7159.609
Wise, R., Hart, T., Cars, O., Streulens, M., Helmuth, R., Huovinen, P., & Sprenger, M. (1998). Antimicrobial resistance. BMJ, 317(7159), 609–610. https://doi.org/10.1136/bmj.317.7159.609
Wise, R., Hart, T., Cars, O., Streulens, M., Helmuth, R., Huovinen, P., & Sprenger, M. (1998). Antimicrobial resistance. BMJ, 317(7159), 609–610. https://doi.org/10.1136/bmj.317.7159.609
Wise, R., Hart, T., Cars, O., Streulens, M., Helmuth, R., Huovinen, P., & Sprenger, M. (1998). Antimicrobial resistance. BMJ, 317(7159), 609–610. https://doi.org/10.1136/bmj.317.7159.609
World Health Organisation. (2018, February 15). Antimicrobial resistance. Who.int; World Health Organization: WHO. https://www.who.int/en/news-room/fact-sheets/detail/antimicrobial-resistance
Simonsen, G. S. (2018). Antimicrobial resistance surveillance in Europe and beyond. Eurosurveillance, 23(42). https://doi.org/10.2807/1560-7917.es.2018.23.42.1800560
Rogers, S. (2013, March 11). Antibiotics and drug resistance: how do we compare? The Guardian. https://www.theguardian.com/news/datablog/2013/mar/11/antibiotic-drug-resistance
Hadley Wickham (2010) A Layered Grammar of Graphics, Journal of Computational and Graphical Statistics, 19:1, 3-28, DOI: 10.1198/jcgs.2009.07098
Riederer, Y. X., Christophe Dervieux, Emily. (n.d.). Acknowledgments | R Markdown Cookbook. In bookdown.org. Retrieved September 17, 2023, from https://bookdown.org/yihui/rmarkdown-cookbook/acknowledgments.html
Baglin, J. (2023). Data Visualisation: From Theory to Practice. In Data Visualisation and Communication (2350) [Online Textbook]. RMIT University. Retrieved from https://dark-star161610.appspot.com/secured/_book/index.html